package cn.netbox.spring.pojo;

import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * description:
 * date: 2021/11/27 19:26
 * author: Alex
 * version: 1.0
 */
//@Component
//@Component(value = "myStudent")
@Component("myStudent")
public class Student {
    @Value("${myName}")
    private String name;
    // 直接写在属性上面
    @Value("${myId}")
    private int id;
    // Autowired有属性 required 默认值是true
    // 当值为true,如果自动注入失败,则终止程序,抛出错误
    @Autowired(required = false)
    private School school;
    // byType ,使用byName
    @Resource(name = "myHome")
    private Home home;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", id=" + id +
                ", school=" + school +
                ", home=" + home +
                '}';
    }
}
